﻿
<link rel="stylesheet" href="__STATIC__/css/pccomment.css"> 
<div class="WapCommentBox">
	<ul class="PostCommentBox1">
		<ol><i class="fa fa-edit"></i><textarea placeholder="发布您的精彩评论"></textarea></ol>
		<li><button type="butter" onclick="post_commentPc()">发表</button></li>		
	</ul>
	<div class="head">
		<div class="tag">全部评论({$total})</div>
	</div>
	<div class="ListComment">
		{volist name="listdb" id="rs"}
		<ul class="lists" id="comment_cnt_{$rs.id}">
			<ol class="icon"><a href="{:get_url('user',$rs.uid)}" target="_blank"><img src="{$rs.icon}" onerror="this.src='__STATIC__/images/nobody.gif'"/></a></ol>
			<li class="infos">
				<dl>
					<dt><a href="{:murl('member/msg/add',['uid'=>$rs.uid])}" class="_pop">{$rs.username}</a> <span>{$rs.time}</span></dt>
					<dd>
						<em onclick="dingcomment({$rs.id})"><i class="si si-like"></i> <a class="agree{$rs.id}">{$rs.agree}</a></em> 
						<span onclick="post_comment({$rs.id})"><i class="fa fa-commenting-o"></i> 回复</span>
						{if $rs.uid==login_user('uid')||login_user('groupid')==3}<span onclick="del_comment({$rs.id})"><a href="javascript:"><i class="fa fa-close"></i> 删除</a></span>{/if}
					</dd>
				</dl>
				<div class="comment">{$rs.content}</div>				
				<div class="repalyinfs repalyinfs{$rs.id}">
					{volist name="rs.children" id="vo"}
					<div id="comment_cnt_{$vo.id}">
						<a href="{:get_url('user',$vo.uid)}" target="_blank">{$vo.username|default='游客'}：</a>
						{$vo.content} 
						{if $rs.uid==login_user('uid')||login_user('groupid')==3}<span onclick="del_comment({$vo.id})" style="float:right;"><a href="javascript:"><i class="fa fa-close"></i> 删除</a></span>{/if}
					</div>
					{/volist}
				</div>
			</li>
		</ul>
		{/volist}
	</div>
	<div class="ShowMoreComment"><button type="butter" onclick="ShowMoreComment()">更多评论 <i class="fa fa-angle-double-down"></i></button></div>
</div>
<script type="text/javascript">
	var posturl,baseurl;
	posturl=baseurl="{posturl}";
	var repalyid=0;
	var commentpage=1;
	function post_comment(pid){			
		if(pid>0){
			repalyid=pid;
			posturl=baseurl+"?pid="+pid;
		}
		layer.open({
		  type: 1,
		  skin: 'layui-layer-demo', //样式类名
		  area: ['320px', '280px'], //宽高
		  closeBtn: 0, //不显示关闭按钮
		  anim: 2,
		  shadeClose: true, //开启遮罩关闭
		  content: '<ul class="PostCommentBox"><ol><textarea placeholder="请输入评论内容"></textarea></ol><li><button type="butter" onclick="post_comment1()">发表</button><button type="butter" onclick="layer.closeAll()">取消</button></li></ul>'
		});
	}
	
function del_comment(id){
	layer.confirm('你确认要删除吗？',function(){
		$.get("{:purl('comment/api/delete')}?ids="+id,function(res){
			if(res.code==0){
				layer.msg('删除成功');
				$("#comment_cnt_"+id).hide();
			}else{
				layer.alert(res.msg);
			}
		});
	});
}

	//引用评论
	function post_comment1(){
		var contents=$('.PostCommentBox textarea').val();
		if(contents==''){
			layer.alert("请输入评论内容！");
		}else{
			$.post(
				posturl,
				{content:contents},
				function(res,status){
					if(res.code==0){
						if(repalyid>0){
							$('.repalyinfs'+repalyid).html(res.data);
						}else{
							$('.ListComment').html(res.data);
							commentpage=1;
							//$('.ShowMoreComment').fadeIn();
						}
						layer.closeAll(); //疯狂模式，关闭所有层
						layer.msg('发表成功！');
						HiddenShowMoreComment();
					}else{
						layer.alert('评论发表失败:'+res.msg);
					}
				}
			);				
		}			
	}
	
	
	function post_commentPc(){
		var contents=$('.PostCommentBox1 textarea').val();
		if(contents==''){
			layer.alert("请输入评论内容！");
		}else{
			$('.PostCommentBox1 textarea').val('评论发表中……');
			$('.PostCommentBox1 li').html('<span>发表中</span>');
			$.post(
				posturl,
				{content:contents},
				function(res,status){
					$('.PostCommentBox1 textarea').val('');
					$('.PostCommentBox1 li').html('<button type="butter" onclick="post_commentPc()">发表</button>');
					if(res.code==0){
						$('.ListComment').html(res.data);
						commentpage=1;
						layer.msg('发表成功！');
						HiddenShowMoreComment();
					}else{
						layer.alert('评论发表失败:'+res.msg);
					}
				}
			);				
		}
	}

	function dingcomment(id){
			var agree=parseInt($('.agree'+id).html());
			$.get('{posturl}?agree=1&id='+id+'&'+Math.random(),function(res){
				if(res.code==0){
					agree++;
					$('.agree'+id).html(agree);
					layer.msg('点赞成功！');
				}else{
					layer.alert('点赞失败:'+res.msg);
				}
			});
	}
		
	function ShowMoreComment(){
			commentpage++;
			$.get('{pageurl}?page='+commentpage+'&'+Math.random(),function(res){
				if(res.code==0){
					if(res.data==''){
						layer.msg('显示完了！');
						$('.ShowMoreComment').fadeOut();
					}else{
						res.data="<div class='pages"+commentpage+"'>"+res.data+"</div>";			
						$('.ListComment').append(res.data);
						$('.ListComment .pages'+commentpage).hide();
						$('.ListComment .pages'+commentpage).show(500);
					}
				}else{
					layer.msg(res.msg,{time:2500});
				}
			});
	}

	function HiddenShowMoreComment(){
			var Comments=$('.ListComment .lists').length;
			if(parseInt(Comments/{$cfg_array.rows})<1){
				$('.ShowMoreComment').hide();
			}else{
				$('.ShowMoreComment').show();
			}
	}

	HiddenShowMoreComment();
</script>